﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.HVAC
{
	public partial class EquipmentCoilSettingForm : System.Windows.Forms.Form
	{
		public EquipmentCoilSettingForm(Autodesk.Revit.DB.Document document)
		{
			this.InitializeComponent();
			base.Icon = Resource.YArchitechIcon;
			this.initParameterSetting();
			new YJKProcessTools().ShowInTaskbarChange(this);
			this.doc = document;
		}

		private void initParameterSetting()
		{
			EquipmentCoilSetParam equipmentCoilSetText = this.userSetting.GetEquipmentCoilSetText();
			try
			{
				this.hytbSupply.Text = equipmentCoilSetText.SupplyWater.ToString();
				this.hytbReturn.Text = equipmentCoilSetText.ReturnWater.ToString();
				this.hytbCool.Text = equipmentCoilSetText.CoolWater.ToString();
				this.hytbName.Text = equipmentCoilSetText.DefaultValve;
			}
			catch (Exception)
			{
			}
		}

		private void UserSettingWrite()
		{
			try
			{
				EquipmentCoilSetParam equipmentCoilSetParam = new EquipmentCoilSetParam();
				equipmentCoilSetParam.SupplyWater = double.Parse(this.hytbSupply.Text.Trim());
				equipmentCoilSetParam.ReturnWater = double.Parse(this.hytbReturn.Text.Trim());
				equipmentCoilSetParam.CoolWater = double.Parse(this.hytbCool.Text.Trim());
				equipmentCoilSetParam.DefaultValve = this.hytbName.Text.Trim();
				this.userSetting.WriteEquipmentCoilSetText(equipmentCoilSetParam);
			}
			catch (Exception)
			{
			}
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			this.UserSettingWrite();
			base.DialogResult = DialogResult.OK;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void btnChoose_Click(object sender, EventArgs e)
		{
			DuctAccessoryForm ductAccessoryForm = new DuctAccessoryForm(new SpaceFamilyDataReader().GetAllNameAndImage2DByCategory("PipeValve", 0), this.doc, "pipe", "ConnectionSetting", "PipeValve");
			if (ductAccessoryForm.ShowDialog() == DialogResult.OK)
			{
				this.hytbName.Text = ductAccessoryForm.strFamilyName;
			}
		}

		private HVACUserSetting userSetting = new HVACUserSetting();

		private Document doc;
	}
}
